package com.fhz.a2102shopjava.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;

/**
 * 时间:2023/8/15
 *
 * @author Mr.Feng
 * 简述: TODO
 */
public abstract class BaseFragment<VM extends BaseViewModel ,DB extends ViewDataBinding>  extends Fragment {
    protected VM mViewModel;
    protected DB mBinding;

    protected abstract int getLayoutId();
    protected abstract void initData();
    protected abstract VM createViewModel();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        mBinding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false);

        mViewModel = createViewModel();
        initData();
        return mBinding.getRoot();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mBinding =  null;
    }
}
